$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        boxList: null,
        online: null,
        type: null,
        schoolId: null,
        health: null,
        init: function () {
            this.boxList = new xhDataGrid($('#boxList'), 'box/getBox');
            this.boxList.parseToolbar().init();
            this.funObj().expandDetial();
            // this.funObj().initLoop();
            // $this.boxList.onLoadSuccess = function () {
            //     //全部展开
            //     var row = $this.boxList.command("getRows");
            //     for (var r = 0; r < row.length; r++)
            //     {
            //         $this.boxList.command("expandRow",r);
            //     }
            // };
            this.listener();
        },
        listener: function () {
            var $this = this;
            //downerror list
            $('#downError').click(function () {
                $this.funObj().downErrorList();
            });
            $('#downList').click(function () {
                $this.funObj().downList();
            });
            //搜索
            $('#bt_search').click(function () {
                $this.online = $('#online').val();
                $this.type = $('#boxType').val();
                $this.health = $('#health').val();
                $this.funObj().searchBoxList();
            });
            //双击编辑盒子信息
            $this.boxList.onDblClickRow = function (rowIndex, rowData) {
                var url = 'box/boxForm?schoolId=' + rowData.schoolId + '&appId=' + rowData.appId + '&code=' + rowData.code + '&schoolName=' + rowData.schoolName +
                    '&downloadReportSwitch=' + rowData.downloadReportSwitch + '&downloadFailedReportSwitch=' + rowData.downloadFailedReportSwitch +
                    '&downloadLimitRateSwitch=' + rowData.downloadLimitRateSwitch + '&uploadLimitRateSwitch=' + rowData.uploadLimitRateSwitch +
                    '&downBandwidth=' + rowData.downBandwidth + '&upBandwidth=' + rowData.upBandwidth + '&mac=' + rowData.mac;
                window.top.xhTop.showModal({
                    title: '编辑盒子',
                    width: 660,
                    content: '<iframe src="' + url + '" style="width: 100%;border-style: none;padding: 0px;height: 300px"  scrolling="yes"   ></iframe>',
                    backClose: true,
                    button: '提交',
                });
            };

        },
        funObj: function () {
            var $this = this;
            return {
                expandDetial: function () {
                    $this.boxList.command({
                        view: detailview,
                        detailFormatter: function (index, row) {
                            return '<div class="ddv" style="border: 0px"></div>';
                        },
                        onExpandRow: function (index, row) {
                            var ddv = $(this).datagrid('getRowDetail', index).find('div.ddv');
                            var content =
                                '<table>' +
                                '<tr>' +
                                '<td width="160" style="text-align: center;border-left:1px dotted #ddd;line-height: 25px;">' +
                                ' 外网下载次数: ' + row.externalDownloadCnt + '</td>' +
                                '<td width="160" style="text-align: center;line-height: 25px;"> ' +
                                '外网下载成功次数: ' + row.externalDownloadSuccessCnt + '</td>' +
                                '<td width="160" style="line-height: 25px;text-align: center;">' +
                                ' 外网下载失败次数: ' + row.externalDownloadFailedCnt + '</td>' +
                                '<td width="160" style="line-height: 25px;text-align: center;">' +
                                ' 内网下载次数: ' + row.internalDwonloadCnt + '</td>' +
                                '<td width="140" style="line-height: 25px;text-align: center;">' +
                                ' 外网上传次数: ' + row.externalUploadCnt + '</td>' +
                                '<td width="140" style="line-height: 25px;text-align: center;">' +
                                ' 外网上传成功次数: ' + row.externalUploadSuccessCnt + '</td>' +
                                '<td width="140" style="line-height: 25px;text-align: center;">' +
                                ' 外网上传失败次数: ' + row.externalUploadFailedCnt + '</td>' +
                                '<td width="150" style="line-height: 25px;text-align: center;">' +
                                ' 内网上传次数: ' + row.internalUploadCnt + '</td>' +
                                '</tr>' +
                                '<tr>' +
                                '<td    width="160" style=" line-height:25px;border-left:1px dotted #ddd;text-align: center"> ' +
                                '每秒接收速度: ' + row.preReceiveRate + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center"> ' +
                                '每秒发送速度: ' + row.preTransmitRate + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center"> ' +
                                '最高接收速度: ' + row.highPreReceiveRate + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center">' +
                                '最高发送速度: ' + row.highPreTransmitRate + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center"> ' +
                                '最低接收速度: ' + row.lowPreReceiveRate + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center"> ' +
                                '最低发送速度: ' + row.lowPreTransmitRate + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center"> ' +
                                '平均接收速度: ' + row.avgReceiveRate + '</td>' +
                                '<td width="150" style=" line-height: 25px;text-align: center">' +
                                '平均发送速度: ' + row.avgTransmitRate + '</td>' +
                                '</tr>' +
                                '<tr>' +
                                '<td width="160" style=" line-height:25px;border-left:1px dotted #ddd;text-align: center"> ' +
                                '外网下载速度: ' + row.externalDownloadRate + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center"> ' +
                                '外网下载限速: ' + row.externalDownloadLimitRate + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center;">' +
                                ' 下载中的流量: ' + row.downloadingFlow + '</td>' +
                                '<td  width="160" style=" line-height: 25px;text-align: center;">' +
                                ' 上传中的流量: ' + row.uploadingFlow + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center;">' +
                                '外网上传速度: ' + row.externalUploadRate + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center;">' +
                                '外网上传限度: ' + row.externalUploadLimitRate + '</td>' +
                                '</tr>' +
                                '<tr>' +
                                '<td width="160" style=" text-align: center;border-left:1px dotted #ddd;line-height: 25px;">' +
                                '微服务Id: ' + row.iServerId + '</td>' +
                                '<td width="160" style=" text-align: center;line-height: 25px;"> ' +
                                '心跳次数: ' + row.hbTimes + '</td>' +
                                '<td width="160" style=" line-height: 25px;text-align: center;">' +
                                '访问次数: ' + row.accessCnt + '</td>' +
                                '<td width="280" colspan="2" style=" line-height: 25px;text-align: center;">' +
                                '上次访问时间: ' + row.lastAccessTime + '</td>' +
                                '<td width="140" style=" line-height: 25px;text-align: center;">' +
                                ' 外网Ip: ' + row.wanIp + '</td>' +
                                '<td width="140"  style=" line-height: 25px;text-align: center;;border-top:1px dotted #ddd;">' +
                                '内网Ip: ' + row.lanIp + '</td>' +
                                '</tr>' +
                                '<tr>' +
                                '<td    width="350" colspan="4" style="text-align: left; line-height:25px;border-left:1px dotted #ddd;"> ' +
                                '2\\5\\10分钟平均接收速:  ' + row.twoMinuteAvgReceiveRate + '\\' + row.fiveMinuteAvgReceiveRate + '\\' +
                                row.tenMinuteAvgReceiveRate + '</td>' +
                                '<td    width="350" colspan="4" style="text-align: left; line-height:25px;border-left:1px dotted #ddd;""> ' +
                                '2\\5\\10分钟平均发送速:  ' + row.twoMinuteAvgTransmitRate + '\\' + row.fiveMinuteAvgTransmitRate + '\\' +
                                row.tenMinuteAvgTransmitRate + '</td>' +
                                '</tr>' +
                                '</table>';
                            ddv.panel({
                                border: true,
                                content: content,
                            });
                            $this.boxList.command('fixDetailRowHeight', index);
                            $('.ddv td').mouseover(function () {
                                $(this).css('background-color', '#c4e3f3');
                            });
                            $('.ddv td').mouseout(function () {
                                $(this).css('background-color', '#fff');
                            });
                        }
                    });
                },
                initLoop: function () {
                    setInterval(function () {
                        $this.boxList.reload();

                    }, 2000)

                },
                searchBoxList: function () {
                    $this.boxList.reload({online: $this.online, type: $this.type, health: $this.health});
                },
                downErrorList: function () {
                    var box = $this.boxList.command('getSelected');
                    if(box){
                        var url = 'box/boxFileErrorList?mac='+box.mac;
                        window.top.xhTop.showModal({
                            title: '下载失败上报列表',
                            width: 800,
                            content: '<iframe src="' + url + '" style="width: 100%;border-style: none;padding: 0px;height: 500px"  scrolling="yes"   ></iframe>',
                            backClose: true,
                        });
                    }
                },
                downList: function () {
                    var box = $this.boxList.command('getSelected');
                    if(box){
                        var url = 'box/boxFileList?mac='+box.mac;
                        window.top.xhTop.showModal({
                            title: '下载上报列表',
                            width: 800,
                            content: '<iframe src="' + url + '" style="width: 100%;border-style: none;padding: 0px;height: 500px"  scrolling="yes"   ></iframe>',
                            backClose: true,
                        });
                    }
                }
            }
        }
    }
};
